package com.cl.edu.service.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cl.core.orm.Page;
import com.cl.core.orm.SearchFilter;
import com.cl.core.orm.hibernate.HibernateWebUtils;
import com.cl.core.web.struts2.Struts2Utils;
import com.cl.edu.dao.TsDAO;
import com.cl.edu.entity.Ts;

/**
 * 投诉建议相关操作
 * @author Administrator
 *
 */
@Service
@Transactional
public class TssManager {
	@Autowired
	private TsDAO tsDAO;
	
	/**
	 * 分页查询投诉信息 
	 * @param page
	 * @return
	 */
	public Page<Ts> getTsPage(Page<Ts> page) {
		StringBuffer hql = new StringBuffer("from Ts model");
		hql.append(" where 1=1 ");
		List<SearchFilter> filters = HibernateWebUtils.buildSearchFilters(
				Struts2Utils.getRequest(), "filter_");
		for (SearchFilter filter : filters) {
			if ("isReplay".equals(filter.getPropertyName())) {
				hql.append(" and model.isReplay = ")
						.append(filter.getPropertyValue());
			}
		}
		hql.append(" order by model.").append(page.getOrderBy()).append(" ").append(page.getOrder());
		page = tsDAO.findPage(page, hql.toString());
		return page;
	}
	
	/** 
	 * 根据id查询投诉信息
	 * @param id
	 * @return
	 */
	public Ts getTs(Integer id){
		return tsDAO.get(id);
	}
	
	/**
	 * 更新投诉信息
	 * @param entity
	 */
	public void updateTs(Ts entity) {
		tsDAO.saveOrUpdate(entity);
	}
	
	/**
	 * 删除投诉信息
	 * @param id
	 */
	public void deleteTs(Integer id) {
		tsDAO.delete(id);
	}
}
